home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-19 / iritsm3s.zip / MATHERR.C < prev    next >
C/C++ Source or Header  |  1992-01-25  |  3KB  |  99 lines

  1. /*****************************************************************************
  2. *   "Irit" - the 3d polygonal solid modeller.                     *
  3. *                                         *
  4. * Written by:  Gershon Elber                Ver 0.2, Mar. 1990   *
  5. ******************************************************************************
  6. * Module to handle floating point errors:                     *
  7. *****************************************************************************/
  8.  
  9. #ifdef __MSDOS__
  10. #include <float.h>
  11. #endif /* __MSDOS__ */
  12.  
  13. #include <math.h>
  14. #include <string.h>
  15. #include <stdio.h>
  16. #include "program.h"
  17. #include "windows.h"
  18. #include "graphgen.h"
  19.  
  20. static int MathErrorNum = 0;
  21. static char MathErrorFunc[LINE_LEN] = "";
  22.  
  23. #ifdef __MSDOS__
  24.  
  25. /*****************************************************************************
  26. * Routine to trap math errors -    set GlobalMathError to error number, and     *
  27. * GlobalMathFunc to the    math function with the error. Return TRUE to         *
  28. * make it believe that everything is ok. now...                     *
  29. *****************************************************************************/
  30. int cdecl matherr(struct exception *except)
  31. {
  32.     strcpy(MathErrorFunc, except -> name);
  33.     MathErrorNum = except -> type;
  34.     except -> retval = 1.0;           /* return something reasonable... */
  35.  
  36.     return TRUE;
  37. }
  38.  
  39. #endif /* __MSDOS__ */
  40.  
  41. /*****************************************************************************
  42. * Routine to return last floating point (function) error if was one:         *
  43. *****************************************************************************/
  44. int MathError(char **FuncName)
  45. {
  46.     int Temp;
  47.  
  48.     *FuncName = MathErrorFunc;
  49.  
  50.     Temp = MathErrorNum;
  51.     MathErrorNum = 0;
  52.     return Temp;
  53. }
  54.  
  55. /*****************************************************************************
  56. * Routine to print lower level floating point error message.             *
  57. * This routine should be called by SIGFPE signal trapping handler.         *
  58. *****************************************************************************/
  59. void PrintFPError(int Type)
  60. {
  61.     char s[LINE_LEN];
  62.  
  63.     strcpy(s, "Fatal Floating Point Error: ");
  64.  
  65.     switch (Type) {
  66. #ifdef __MSDOS__
  67.     case FPE_INTOVFLOW:
  68.         strcat(s, "integer overflow");
  69.         break;
  70.     case FPE_INTDIV0:
  71.         strcat(s, "integer divide by zero");
  72.         break;
  73.     case FPE_INVALID:
  74.         strcat(s, "invalid operation");
  75.         break;
  76.     case FPE_ZERODIVIDE:
  77.         strcat(s, "division by zero");
  78.         break;
  79.     case FPE_OVERFLOW:
  80.         strcat(s, "numeric overflow");
  81.         break;
  82.     case FPE_UNDERFLOW:
  83.         strcat(s, "numeric underflow");
  84.         break;
  85.     case FPE_INEXACT:
  86.         strcat(s, "precision lost");
  87.         break;
  88.     case FPE_EXPLICITGEN:
  89.         strcat(s, "explicit signal");
  90.         break;
  91. #endif /* __MSDOS__ */
  92.     default:
  93.         strcat(s, "Undefined error");
  94.         break;
  95.     }
  96.  
  97.     WndwInputWindowPutStr(s);
  98. }
  99.